
#ifndef _MEMBER_BWIDGET_H_
#define _MEMBER_BWIDGET_H_

#include <BOpenGL>
#include <BEvent>
#include <BRect>
#include <BFont>
#include <BCursor>
#include <BLayout>
#include <BStyle>
#include <BAnimation>
#include <BSizePolicy>
#include <BSizeStretch>
#include <BDisplay>

#include <BWidget>
#include "IWindow.h"
#include "IPaint.h"
#include "IStyleDriver.h"

#define widget_member(widget)		((member_BWidget*)((BWidget*)widget)->_ptr)

namespace BWE
{
	class member_BWidget
	{
	public:
		member_BWidget(BWidget* widget);
		~member_BWidget();

		void frame();

		void syncWindowPos(const BPoint& wpos);
		void syncWindowSize(const BSize& wsize);

		void procEvent(const BEvent& event);

		void applyStyleDriver();

		BStyle* lowerStyle();
		void changeStyle(BChangeEvent& changeEvent);
		void applyStyle(const BStyle* realStyle);
		void dirtyLayouts(bool raise = true);
		void adjustRects();
		void adjustLayouts();

	public:
		BWidget*				boss;
		IPaint					paint;
		IWindowHolder			window;
		BDisplay*				display;
		BRect					absoluteRect;
		BRect					globalRect;

		bool					refresh;
		bool					dirty;
		bool					fbo_resized;
		GLuint					fbo;
		GLuint					rbo_depth;
		GLuint					tbo;

		BString					title;
		BString					tips;
		bool					visible;
		bool					modal;
		bool					focus;
		bool					floating;
		bool					droppable;

		BPoint					pos;
		BSize					size;
		BSize					minSize;
		BSize					maxSize;
		BSizeStretch			sizeStretch;
		BSizePolicy				sizePolicy;

		BLayout*				layout;
		BHolder<BLayout>		titleLayout;
		BHolder<BLayout>		mainLayout;
		BHolder<BLayout>		topLayout;
		BHolder<BLayout>		leftLayout;
		BHolder<BLayout>		rightLayout;
		BHolder<BLayout>		bottomLayout;
		BArray<BLayoutHolder>	freeLayouts;

		BHolder<BCursor>		cursor;
		BHolder<BAnimation>		animation;
		BHolder<BStyle>			style;
		BHolder<IStyleDriver>	styleDriver;
		BString					styleSheet;

		BWidget*				parent;
		BList<BWidgetHolder>	children;

		int						border;
		BPerchs					perchs;
		BMargins				margins;

		bool					dirtyRect;
		BRect					rectTitle;
		BRect					rectLeft;
		BRect					rectTop;
		BRect					rectClient;
		BRect					rectRight;
		BRect					rectBottom;

		bool					roundCorner;
		BRect					border_left_top_rect;
		BRect					border_lett_bottom_rect;
		BRect					border_right_top_rect;
		BRect					border_right_bottom_rect;

		BRect					perch_left_top_rect;
		BRect					perch_left_bottom_rect;
		BRect					perch_right_top_rect;
		BRect					perch_right_bottom_rect;

		BRect					margin_left_top_rect;
		BRect					margin_left_bottom_rect;
		BRect					margin_right_top_rect;
		BRect					margin_right_bottom_rect;
	};
}

#endif
